package com.hyt.it.ogt.pj.asynchronous;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.pj.feign.KwClient;
import com.hyt.it.ogt.pj.model.vo.TaskVo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class BatchUpdateStudentStatusKw implements Runnable {

	private List<TaskVo> taskVos = new ArrayList<TaskVo>();
	private KwClient kwClient;
	private Integer kwStatus;

	public List<TaskVo> getTaskVos() {
		return taskVos;
	}

	public void setTaskVos(List<TaskVo> taskVos) {
		this.taskVos = taskVos;
	}

	public KwClient getKwClient() {
		return kwClient;
	}

	public void setKwClient(KwClient kwClient) {
		this.kwClient = kwClient;
	}

	public Integer getKwStatus() {
		return kwStatus;
	}

	public void setKwStatus(Integer kwStatus) {
		this.kwStatus = kwStatus;
	}

	@Override
	public void run() {
		try {
			log.info("# BatchUpdateStudentStatusKw start taskVos:{}", JSON.toJSON(taskVos));
			if (CollectionUtils.isNotEmpty(taskVos)) {
				for (TaskVo taskVo : taskVos) {
					// 调用考务设置为缺席
					log.info("同步修改考生状态项目id：{}, 考生准考证：{},状态码：{}", taskVo.getProjectId(), taskVo.getAdmissionNum(), kwStatus);
					ApiResponse<Object> result = kwClient.updateCandidateAbsent(taskVo.getProjectId(), taskVo.getAdmissionNum(), kwStatus);
					log.info("同步修改考生状态 result:{}", result);
				}
			}
			log.info("# BatchUpdateStudentStatusKw end");
		} catch (Exception e) {
			log.error("# BatchUpdateStudentStatusKw error", e);
		}
	}
}
